import { useTable, LIST_TYPE } from '@crud/index';
import { getColonelList } from '@/api/crm-agency/kgj/colonel';

// 查询

const levelMap: Record<number | string, string> = { 1: '初级', 2: '高级' };
// 表格
export const useTableList = (options: any = {}) => {
  const columns: any = [
    { label: '代理名称', prop: 'name', minWidth: 200, fixed: 'left' },
    { label: '代理手机号', prop: 'mobile', minWidth: 120 },
    { label: '代理类型', prop: 'level', minWidth: 120, render: (s:any) => levelMap[s.row.level] || '-' },
    { label: '账号余额', prop: 'balance', minWidth: 120 },
    { label: '加入时间', prop: 'add_time', minWidth: 160, type: 'date' },
    { label: '赠送/兑换码', prop: 'code', minWidth: 120, render: 'code' },
    { label: '新/老用户数', prop: 'user', minWidth: 120, render: 'user' },
    { label: '订单总数', prop: 'order_count', minWidth: 120, render: 'order_count' },
    { label: '订单总额', prop: 'total_fee', minWidth: 120 },
    { label: '佣金余额', prop: 'commission_fee', minWidth: 120 },
    { label: '佣金总数', prop: 'commission_total', minWidth: 120 },
    { label: '保证金', prop: 'safty', minWidth: 120 },
    { label: '操作', align: 'center', minWidth: 360, render: 'actions', fixed: 'right' }
  ];

  return useTable({
    ...options,
    type: LIST_TYPE.AGENCY,
    params: {
      keyword: '',
      from_dt: undefined,
      to_dt: undefined
    },
    columns: columns,
    getParams: ({ _timeArr = [], ...params }) => {
      // 处理时间参数
      if (_timeArr?.length) {
        const [begin, end] = _timeArr;
        params.from_dt = begin;
        params.to_dt = end;
      }
      return params;
    },
    getList: getColonelList
  });
};
